-<?php
+<?php
/**
* This file is only included if profiling is enabled
* @package MediaWiki
class Profiler {
var $mStack = array (), $mWorkStack = array (), $mCollated = array ();
var $mCalls = array (), $mTotals = array ();
-
+
function Profiler()
{
// Push an entry for the pre-profile setup time onto the stack
} else {
$this->profileIn( '-total' );
}
-
+
}
function profileIn($functionname) {
global $wgDebugFunctionEntry;
$wgDebugFunctionEntry = false;
- if (!count($this->mStack)) {
+ if (!count($this->mStack) && !count($this->mCollated)) {
return "No profiling output\n";
}
$this->close();
trim( sprintf( "%7.3f", $delta * 1000.0 ) ),
$space, $fname );
}
-
+
function micro2Float( $micro ) {
list( $whole, $fractional ) = explode( ' ', $micro );
return (float)$whole + (float)$fractional;
}
-
+
function microDelta( $start, $end ) {
return $this->micro2Float( $end ) -
$this->micro2Float( $start );
return $ru['ru_utime.tv_sec'].' '.$ru['ru_utime.tv_usec'] / 1e6;
}
- function getFunctionReport() {
+ function getFunctionReport() {
$width = 140;
$nameWidth = $width - 65;
$format = "%-{$nameWidth}s %6d %13.3f %13.3f %13.3f%% %9d (%13.3f -%13.3f) [%d]\n";
$fname = 'Profiler::logToDB';
$dbw = & wfGetDB(DB_MASTER);
+ if (!is_object($dbw))
+ return false;
$profiling = $dbw->tableName('profiling');
$name = substr($name, 0, 255);
$rc = $dbw->affectedRows();
if ($rc == 0) {
- $dbw->insert('profiling', array ('pf_name' => $name, 'pf_count' => $eventCount,
+ $dbw->insert('profiling', array ('pf_name' => $name, 'pf_count' => $eventCount,
'pf_time' => $timeSum, 'pf_server' => $wguname['nodename'] ), $fname, array ('IGNORE'));
}
// When we upgrade to mysql 4.1, the insert+update
// can be merged into just a insert with this construct added:
// "ON DUPLICATE KEY UPDATE ".
// "pf_count=pf_count + VALUES(pf_count), ".
- // "pf_time=pf_time + VALUES(pf_time)";
+ // "pf_time=pf_time + VALUES(pf_time)";
}
/**
}
-$wgProfiler = new Profiler();
-
?>